﻿
Partial Class mtProductslPopup
    Inherits System.Web.UI.Page
    Public AlertText As String
    Public ScriptText As String

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        If Session("users") Is Nothing Then
            ScriptText = "<script> window.parent.TINY.box.hide();</script>"
        End If
        If IsPostBack = False Then
            L_CommentDetail.Text = "รายละเอียดผลิตภัณฑ์"

            L_CmmtYear.Text = Request("IDYear")
            L_ID.Text = Request("PID")
            Session("L_ProductYear") = L_CmmtYear.Text


            If Val(L_ID.Text) <> 0 Then
                If IsPostBack = False Then
                    getData(Val(L_ID.Text))
                End If

            Else
                L_CmmtYear.Text = Request("PlanYear")
                PlanYearsTxt.Text = Request("PlanYear")
            End If

        End If

    End Sub

    Protected Sub AddBtn_Click(sender As Object, e As ImageClickEventArgs) Handles AddBtn.Click
        If IDTxt.Text = "" Then
            Alert("กรุณากรอก รหัสผลิตภัณฑ์")
            Exit Sub
        End If
        If DescripTxt.Text = "" Then
            Alert("กรุณากรอก ชื่อผลิตภัณฑ์")
            Exit Sub
        End If
        If CompensateRateTxt.Text = "" And FormCheckBoxList.Items(0).Selected = True Then
            Alert("กรุณากรอก อัตราค่าตอบแทนสินเชื่อ")
            Exit Sub
        End If
        'If CaLcuTypeGroupCombo.Value = "" Then
        '    Alert("กรุณาเลือก วิธีคำนวณค่าตอบแทน")
        '    Exit Sub
        'End If

        Dim F06, F07, F08, F09, F10, P01, P02, P03, P04 As String
        Dim cF06, cF07, cF08, cF09, cF10, cP01, cP02, cP03, cP04 As String

        If FormCheckBoxList.Items(0).Selected = True Then
            F06 = "Y"
            If CommtItemComboF06.Value = "" Then
                Alert("กรุณาเลือก Commitment Item ที่จะบันทึกค่าในฟอร์มค่าตอบแทนสินเชื่อ")
                Exit Sub
            Else
                cF06 = CommtItemComboF06.Value
            End If
        Else
            F06 = "N"
            cF06 = Nothing
        End If
        If FormCheckBoxList.Items(1).Selected = True Then
            F07 = "Y"
            If CommtItemComboF07.Value = "" Then
                Alert("กรุณาเลือก Commitment Item ที่จะบันทึกค่าในฟอร์มค่าเบี้ยประกันภัยสินเชื่อ")
                Exit Sub
            Else
                cF07 = CommtItemComboF07.Value
            End If
        Else
            F07 = "N"
            cF07 = Nothing
        End If
        If FormCheckBoxList.Items(2).Selected = True Then
            F08 = "Y"
            If CommtItemComboF08.Value = "" Then
                Alert("กรุณาเลือก Commitment Item ที่จะบันทึกค่าในฟอร์มค่าตอบแทนสงเคราะห์ชีวิต")
                Exit Sub
            Else
                cF08 = CommtItemComboF08.Value
            End If
        Else
            F08 = "N"
            cF08 = Nothing
        End If
        If FormCheckBoxList.Items(3).Selected = True Then
            F09 = "Y"
            If CommtItemComboF09.Value = "" Then
                Alert("กรุณาเลือก Commitment Item ที่จะบันทึกค่าในฟอร์มค่าธรรมเนียมบัตรสงเคราะห์ชีวิต")
                Exit Sub
            Else
                cF09 = CommtItemComboF09.Value
            End If
        Else
            F09 = "N"
            cF09 = Nothing
        End If
        If FormCheckBoxList.Items(4).Selected = True Then
            F10 = "Y"
            If CommtItemComboF10.Value = "" Then
                Alert("กรุณาเลือก Commitment Item ที่จะบันทึกค่าในฟอร์มค่าตอบแทนเงินฝาก GP")
                Exit Sub
            Else
                cF10 = CommtItemComboF10.Value
            End If
        Else
            F10 = "N"
            cF10 = Nothing
        End If
        If FormCheckBoxList.Items(5).Selected = True Then
            P01 = "Y"
            'If CommtItemComboP01.Value = "" Then
            '    Alert("กรุณาเลือก CommtItem Code P01")
            '    Exit Sub
            'Else
            '    cP01 = CommtItemComboP01.Value
            'End If
        Else
            P01 = "N"
            cP01 = Nothing
        End If
        If FormCheckBoxList.Items(6).Selected = True Then
            P02 = "Y"
            'If CommtItemComboP02.Value = "" Then
            '    Alert("กรุณาเลือก CommtItem Code P02")
            '    Exit Sub
            'Else
            '    cP02 = CommtItemComboP02.Value
            'End If
        Else
            P02 = "N"
            cP02 = Nothing
        End If
        If FormCheckBoxList.Items(7).Selected = True Then
            P03 = "Y"
            'If CommtItemComboP03.Value = "" Then
            '    Alert("กรุณาเลือก CommtItem Code P03")
            '    Exit Sub
            'Else
            '    cP03 = CommtItemComboP03.Value
            'End If
        Else
            P03 = "N"
            cP03 = Nothing
        End If
        If FormCheckBoxList.Items(8).Selected = True Then
            P04 = "Y"
            'If CommtItemComboP04.Value = "" Then
            '    Alert("กรุณาเลือก CommtItem Code P04")
            '    Exit Sub
            'Else
            '    cP04 = CommtItemComboP04.Value
            'End If
        Else
            P04 = "N"
            cP04 = Nothing
        End If

        Dim adapter As New MasterDataSetTableAdapters.ProductsTableAdapter
        Dim check As Integer
        If CompensateRateTxt.Text.Trim = "" Then
            check = adapter.CheckExistUpdate(IDTxt.Text, Val(PlanYearsTxt.Text), Trim(DescripTxt.Text), L_ProductType.Text, Nothing, CaLcuTypeGroupCombo.Value, Val(L_ID.Text))
        Else
            check = adapter.CheckExistUpdate(IDTxt.Text, Val(PlanYearsTxt.Text), Trim(DescripTxt.Text), L_ProductType.Text, CompensateRateTxt.Text, CaLcuTypeGroupCombo.Value, Val(L_ID.Text))
        End If


        ' Response.Write(check)
        'If Val(L_ID.Text) = 0 Then
        '    If Val(check) <> 0 Then
        '        Alert("ข้อมูลซ้ำกับที่มีอยู่ กรุณาตรวจสอบ")
        '        Exit Sub
        '    Else
        '        adapter.InsertProductPopUp(IDTxt.Text, PlanYearsTxt.Text, Trim(DescripTxt.Text), L_ProductType.Text, CompensateRateTxt.Text, CaLcuTypeGroupCombo.Value, F06, F07, F08, F09, F10, P01, P02, P03, P04, Date.Now, Session("users"))
        '        Alert("เพิ่มข้อมูลเรียบร้อยแล้ว")
        '    End If
        'Else
        If Val(check) > 1 Then
            Alert("ข้อมูลซ้ำกับที่มีอยู่ กรุณาตรวจสอบ")
            Exit Sub
        Else
            If CompensateRateTxt.Text.Trim = "" Then
                If Val(CaLcuTypeGroupCombo.Value) = 0 Then
                    adapter.UpdateProductPopUpByID(IDTxt.Text, PlanYearsTxt.Text, Trim(DescripTxt.Text), L_ProductType.Text, Nothing, Nothing, F06, F07, F08, F09, F10, P01, P02, P03, P04, Date.Now, Session("users"), cF06, cF07, cF08, cF09, cF10, Nothing, Nothing, Nothing, Nothing, Val(L_ID.Text))
                Else
                    adapter.UpdateProductPopUpByID(IDTxt.Text, PlanYearsTxt.Text, Trim(DescripTxt.Text), L_ProductType.Text, Nothing, CaLcuTypeGroupCombo.Value, F06, F07, F08, F09, F10, P01, P02, P03, P04, Date.Now, Session("users"), cF06, cF07, cF08, cF09, cF10, Nothing, Nothing, Nothing, Nothing, Val(L_ID.Text))
                End If
            Else
                If Val(CaLcuTypeGroupCombo.Value) = 0 Then
                    adapter.UpdateProductPopUpByID(IDTxt.Text, PlanYearsTxt.Text, Trim(DescripTxt.Text), L_ProductType.Text, CompensateRateTxt.Text, Nothing, F06, F07, F08, F09, F10, P01, P02, P03, P04, Date.Now, Session("users"), cF06, cF07, cF08, cF09, cF10, Nothing, Nothing, Nothing, Nothing, Val(L_ID.Text))
                Else
                    adapter.UpdateProductPopUpByID(IDTxt.Text, PlanYearsTxt.Text, Trim(DescripTxt.Text), L_ProductType.Text, CompensateRateTxt.Text, CaLcuTypeGroupCombo.Value, F06, F07, F08, F09, F10, P01, P02, P03, P04, Date.Now, Session("users"), cF06, cF07, cF08, cF09, cF10, Nothing, Nothing, Nothing, Nothing, Val(L_ID.Text))
                End If

            End If
            Alert("แก้ไขข้อมูลเรียบร้อยแล้ว")
        End If
        'End If
        ScriptText = "<script> window.parent.TINY.box.hide();</script>"
    End Sub
    Sub Alert(ByVal message As String)
        AlertText += "<script> alert('" & message & "');</script>"
    End Sub
    Sub getData(ByVal id As Decimal)
        Dim show As New MasterDataSetTableAdapters.ProductsTableAdapter
        Dim dt As New MasterDataSet.ProductsDataTable
        dt = show.GetDataByID(Val(id))

        For Each row As MasterDataSet.ProductsRow In dt
            ' L_CmmtYear.Text = row.Cmmt_PlanYear

            IDTxt.Text = row.ProductCode
            PlanYearsTxt.Text = row.PlanYear
            DescripTxt.Text = row.Description
            L_ProductType.Text = row.ProductType

            If row.IsCalculationTypeNull = False Then
                CaLcuTypeGroupCombo.Value = row.CalculationType
                If row.CalculationType = "" Then
                    CaLcuTypeGroupCombo.Value = "0"
                End If
            Else
                CaLcuTypeGroupCombo.Value = "0"
            End If

            'MsgBox(row.CalculationType)

            If row.IsCompensateRateNull = False Then
                If Val(row.CompensateRate) <> 0 Then
                    CompensateRateTxt.Text = Format(row.CompensateRate, "#,##0.00")
                End If
            End If
            If row.IsFormF06FlagNull = False Then
                If row.FormF06Flag = "Y" Then
                    FormCheckBoxList.Items(0).Selected = True
                End If
            End If
            If row.IsFormF07FlagNull = False Then
                If row.FormF07Flag = "Y" Then
                    FormCheckBoxList.Items(1).Selected = True
                End If
            End If
            If row.IsFormF08FlagNull = False Then
                If row.FormF08Flag = "Y" Then
                    FormCheckBoxList.Items(2).Selected = True
                End If
            End If
            If row.IsFormF09FlagNull = False Then
                If row.FormF09Flag = "Y" Then
                    FormCheckBoxList.Items(3).Selected = True
                End If
            End If
            If row.IsFormF10FlagNull = False Then
                If row.FormF10Flag = "Y" Then
                    FormCheckBoxList.Items(4).Selected = True
                End If
            End If
            If row.IsFormP01FlagNull = False Then
                If row.FormP01Flag = "Y" Then
                    FormCheckBoxList.Items(5).Selected = True
                End If
            End If
            If row.IsFormP02FlagNull = False Then
                If row.FormP02Flag = "Y" Then
                    FormCheckBoxList.Items(6).Selected = True
                End If
            End If
            If row.IsFormP03FlagNull = False Then
                If row.FormP03Flag = "Y" Then
                    FormCheckBoxList.Items(7).Selected = True
                End If
            End If
            If row.IsFormP04FlagNull = False Then
                If row.FormP04Flag = "Y" Then
                    FormCheckBoxList.Items(8).Selected = True
                End If
            End If

            If row.IsCmmtCodeF06Null = False Then
                CommtItemComboF06.Value = row.CmmtCodeF06
            End If
            If row.IsCmmtCodeF07Null = False Then
                CommtItemComboF07.Value = row.CmmtCodeF07
            End If
            If row.IsCmmtCodeF08Null = False Then
                CommtItemComboF08.Value = row.CmmtCodeF08
            End If
            If row.IsCmmtCodeF09Null = False Then
                CommtItemComboF09.Value = row.CmmtCodeF09
            End If
            If row.IsCmmtCodeF10Null = False Then
                CommtItemComboF10.Value = row.CmmtCodeF10
            End If
            If row.IsCmmtCodeP01Null = False Then
                CommtItemComboP01.Value = row.CmmtCodeP01
            End If
            If row.IsCmmtCodeP02Null = False Then
                CommtItemComboP02.Value = row.CmmtCodeP02
            End If
            If row.IsCmmtCodeP03Null = False Then
                CommtItemComboP03.Value = row.CmmtCodeP03
            End If
            If row.IsCmmtCodeP04Null = False Then
                CommtItemComboP04.Value = row.CmmtCodeP04
            End If

        Next
    End Sub

    Protected Sub CommtItemComboF06_InitializeDataSource(sender As Object, e As ISNet.WebUI.WebCombo.DataSourceEventArgs) Handles CommtItemComboF06.InitializeDataSource

        Dim adap As New MasterDataSet2TableAdapters.CmmtsTableAdapter
        Dim dt As New MasterDataSet2.CmmtsDataTable
        dt = adap.GetDataByPlanYear(Session("PlanYearTxt"))
        e.DataSource = dt

    End Sub
    Protected Sub CommtItemComboF07_InitializeDataSource(sender As Object, e As ISNet.WebUI.WebCombo.DataSourceEventArgs) Handles CommtItemComboF07.InitializeDataSource

        Dim adap As New MasterDataSet2TableAdapters.CmmtsTableAdapter
        Dim dt As New MasterDataSet2.CmmtsDataTable
        dt = adap.GetDataByPlanYear(Session("PlanYearTxt"))
        e.DataSource = dt

    End Sub
    Protected Sub CommtItemComboF08_InitializeDataSource(sender As Object, e As ISNet.WebUI.WebCombo.DataSourceEventArgs) Handles CommtItemComboF08.InitializeDataSource

        Dim adap As New MasterDataSet2TableAdapters.CmmtsTableAdapter
        Dim dt As New MasterDataSet2.CmmtsDataTable
        dt = adap.GetDataByPlanYear(Session("PlanYearTxt"))
        e.DataSource = dt

    End Sub
    Protected Sub CommtItemComboF09_InitializeDataSource(sender As Object, e As ISNet.WebUI.WebCombo.DataSourceEventArgs) Handles CommtItemComboF09.InitializeDataSource

        Dim adap As New MasterDataSet2TableAdapters.CmmtsTableAdapter
        Dim dt As New MasterDataSet2.CmmtsDataTable
        dt = adap.GetDataByPlanYear(Session("PlanYearTxt"))
        e.DataSource = dt

    End Sub
    Protected Sub CommtItemComboF10_InitializeDataSource(sender As Object, e As ISNet.WebUI.WebCombo.DataSourceEventArgs) Handles CommtItemComboF10.InitializeDataSource

        Dim adap As New MasterDataSet2TableAdapters.CmmtsTableAdapter
        Dim dt As New MasterDataSet2.CmmtsDataTable
        dt = adap.GetDataByPlanYear(Session("PlanYearTxt"))
        e.DataSource = dt

    End Sub
    Protected Sub CommtItemComboP01_InitializeDataSource(sender As Object, e As ISNet.WebUI.WebCombo.DataSourceEventArgs) Handles CommtItemComboP01.InitializeDataSource

        Dim adap As New MasterDataSet2TableAdapters.CmmtsTableAdapter
        Dim dt As New MasterDataSet2.CmmtsDataTable
        dt = adap.GetDataByPlanYear(Session("PlanYearTxt"))
        e.DataSource = dt

    End Sub
    Protected Sub CommtItemComboP02_InitializeDataSource(sender As Object, e As ISNet.WebUI.WebCombo.DataSourceEventArgs) Handles CommtItemComboP02.InitializeDataSource

        Dim adap As New MasterDataSet2TableAdapters.CmmtsTableAdapter
        Dim dt As New MasterDataSet2.CmmtsDataTable
        dt = adap.GetDataByPlanYear(Session("PlanYearTxt"))
        e.DataSource = dt

    End Sub
    Protected Sub CommtItemComboP03_InitializeDataSource(sender As Object, e As ISNet.WebUI.WebCombo.DataSourceEventArgs) Handles CommtItemComboP03.InitializeDataSource

        Dim adap As New MasterDataSet2TableAdapters.CmmtsTableAdapter
        Dim dt As New MasterDataSet2.CmmtsDataTable
        dt = adap.GetDataByPlanYear(Session("PlanYearTxt"))
        e.DataSource = dt

    End Sub
    Protected Sub CommtItemComboP04_InitializeDataSource(sender As Object, e As ISNet.WebUI.WebCombo.DataSourceEventArgs) Handles CommtItemComboP04.InitializeDataSource

        Dim adap As New MasterDataSet2TableAdapters.CmmtsTableAdapter
        Dim dt As New MasterDataSet2.CmmtsDataTable
        dt = adap.GetDataByPlanYear(Session("PlanYearTxt"))
        e.DataSource = dt

    End Sub
End Class
